#include <iostream>
using namespace std;

class Person{
  public:
    Person() {
      cout << "[Person] 无参构造" << endl;
    }
    Person(const char* name, int age) {
      cout << "[Person] 有参构造" << endl;
      strcpy(this->name, name);
      this->age = age;
    }

    Person(const Person& p) {
      cout << "[Person] 拷贝构造" << endl;
      strcpy(name, p.name);
      age = p.age;
    }

    ~Person() {
      cout << "call [Person] 析构函数" << endl;
    }

    int getAge() { return age; }
    char* getName() { return name;}

    void print(const char *);
  private:
    int age;
    char name[12];
};
void Person::print(const char *varName) {
  cout << "[" << varName << "] "
       << "name: " << name
       << " age: " << age
       << endl;
}

void print2(Person p) {
  cout << "[Gloabl Print] "
       << "name: " << p.getAge()
       << " age: " << p.getName()
       << endl;
}

Person getPerson() {
  Person p("Mango", 18);
  p.print("getPerson()::p");
  cout << "getPerson()::p 地址：" << &p << endl;
  return p;
}

void test() {
  Person p1{"Mango", 18};
  p1.print("p1");

  // 场景一
  Person p2 = p1;
  p2.print("p2");

  // 场景二
  Person p3(p2);
  p3.print("p3");
}

void test2() {
  Person p1 = { "Mango", 18 };
}

void test3() {
  Person p = getPerson();
  p.print("outer::p");
  cout << "outer::p 地址" << &p << endl;
}

void test4() {
  // 默认初始化
  Person p;
  p = getPerson();
  p.print("outer::p");
  cout << "outer::p 地址" << &p << endl;
}


int main() {
  test4();
  return 0;
}
